﻿using CurrentCostLibrary;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace CurrentCostTest
{
    
    
    /// <summary>
    ///This is a test class for ReadingParserTest and is intended
    ///to contain all ReadingParserTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ReadingParserTest_Hourly
    {


        private TestContext testContextInstance;
        

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion



        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryHourly_ReturnsCorrectSensorId()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_HOURLY_XML;
            int sensorIdToRead = CurrentCostSampleReadings.CC_EXPECTED_SENSORID;

            //CurrentCostHistory actual;
            var actual = ReadingParser.GetCurrentCostHistory(readingDate, inputFromCurrentCost, sensorIdToRead);
            Assert.IsNotNull(actual);
            Assert.AreEqual(CurrentCostSampleReadings.CC_EXPECTED_SENSORID, actual.SensorId);
        }

        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryHourly_ReturnsCorrectReadingDateTime()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_HOURLY_XML;
            int sensorIdToRead = CurrentCostSampleReadings.CC_EXPECTED_SENSORID;

            var actual = ReadingParser.GetCurrentCostHistory(readingDate, inputFromCurrentCost, sensorIdToRead);
            Assert.IsNotNull(actual);
            var expectedReadingDateTime = new DateTime(2009, 12, 7, 7, 16, 20);
            Assert.AreEqual(expectedReadingDateTime, actual.ReadingDateTime);
        }

        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryHourly_ReturnsCorrectHourlyCount()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_HOURLY_XML;
            int sensorIdToRead = CurrentCostSampleReadings.CC_EXPECTED_SENSORID;

            var actual = ReadingParser.GetCurrentCostHistory(readingDate, inputFromCurrentCost, sensorIdToRead);
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.HourlyReadings);
            Assert.AreEqual(8, actual.HourlyReadings.Count);
        }


        //[TestMethod()]
        //public void GetCurrentCostHistoryTest_HardCoded_HourlyValues()
        //{
        //    DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            
        //    string inputFromCurrentCost = CurrentCostSampleReadings.CC_MONTHLY_XML;
        //    int sensorIdToRead = CurrentCostSampleReadings.CC_EXPECTED_SENSORID;

        //    CurrentCostHistory actual;
        //    actual = ReadingParser.GetCurrentCostHistory(readingDate, inputFromCurrentCost, sensorIdToRead);
        //    Assert.IsNotNull(actual);
        //    Assert.IsNotNull(actual.MonthlyReadings);
        //    Assert.AreEqual(8, actual.MonthlyReadings.Count);

        //    var month1 = actual.MonthlyReadings[1];

        //    Assert.AreEqual(readingMonth.AddMonths(-1), month1.ReadingDateTime);
        //    Assert.AreEqual(331.0, month1.KWh);

        //    var month2 = actual.MonthlyReadings[0];
        //    Assert.AreEqual(readingMonth.AddMonths(-2), month2.ReadingDateTime);
        //    Assert.AreEqual(247.750, month2.KWh);

        //}

        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryHourly_ReturnsCorrectEmptySensor()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_HOURLY_XML;
            int sensorIdToRead = 1;

            var actual = ReadingParser.GetCurrentCostHistory(readingDate, inputFromCurrentCost, sensorIdToRead);
            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.HourlyReadings);
            Assert.AreEqual(8, actual.HourlyReadings.Count);
            foreach (var reading in actual.HourlyReadings)
            {
                Assert.AreEqual((decimal)0.0, reading.AverageWatts);
            }
        }

        [TestMethod()]
        public void CurrentCost_GetCurrentCostHistoryHourly_ReturnsCorrectNoOtherReadings()
        {
            DateTime readingDate = CurrentCostSampleReadings.CC_READING_DATE;
            string inputFromCurrentCost = CurrentCostSampleReadings.CC_HOURLY_XML;
            int sensorIdToRead = CurrentCostSampleReadings.CC_EXPECTED_SENSORID;

            var actual = ReadingParser.GetCurrentCostHistory(readingDate, inputFromCurrentCost, sensorIdToRead);
            Assert.AreEqual(0, actual.MonthlyReadings.Count);
            Assert.AreEqual(0, actual.DailyReadings.Count);
        }
    }
}
